﻿using MES.Desktop.Common;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MES.Desktop.SystemModule.Models
{
    public class MenuModel : DataModelBase
    {
        public string MenuId { get; set; }

        public string MenuIcon { get; set; }

        private string _menuHeader;

        public string MenuHeader
        {
            get { return _menuHeader; }
            set
            {
                SetProperty<string>(ref _menuHeader, value);
                this.ClearErrors();
                if (string.IsNullOrEmpty(_menuHeader))
                {
                    this.RaiseErrors("菜单名不能为空");
                }

                // 名称重复检查，自行添加，参照以下代码，以及DepartModel、FuncModel、PostModel、UserModel
                //if (_funcService != null && _funcService.CheckName(value, FuncId))
                //{
                //    this.RaiseErrors("功能名不能重复");
                //}
            }

        }

        public string TargetView { get; set; }// 双击这个节点的时候打开的页面

        public string ParentId { get; set; }
        public bool IsLastChild { get; set; }

        private int? _menuType;

        public int? MenuType
        {
            get { return _menuType; }
            set { SetProperty<int?>(ref _menuType, value); }
        }


        private bool _isExpanded;
        // 是否展开节点
        public bool IsExpanded
        {
            get { return _isExpanded; }
            set { SetProperty(ref _isExpanded, value); }
        }
        // 子节点
        public ObservableCollection<MenuModel> Children { get; set; } =
            new ObservableCollection<MenuModel>();

        public MenuModel Parent { get; set; }

        private bool _isSelected;

        public bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                SetProperty<bool>(ref _isSelected, value);

                if (!value)
                    foreach (var item in Children)
                    {
                        item.IsSelected = value;
                    }
            }
        }

        // 1，2，3，4，5  记录编号
        public string FuncIds { get; set; }
        // 新建，删除     记录名称
        public string FuncNames { get; set; }
    }

}
